//
//  JSMBaiduMapViewController.m
//  TakeYouTourTogether
//
//  Created by king on 15/12/8.
//  Copyright © 2015年 king. All rights reserved.
//

#import "JSMBaiduMapViewController.h"
#import "locationTool.h"
#import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件

@interface JSMBaiduMapViewController ()<locationToolDelegate>{
    bool isGeoSearch;
}
@property(nonatomic, strong) locationTool *myloca;
@property(nonatomic, strong) UIView *searchView;
@property(nonatomic, strong) NSString *locationName1;

@end

@implementation JSMBaiduMapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBar.translucent = YES;
    self.myloca = [[locationTool alloc]init];
    _myloca.delegate = self;
    
//    self.locationName = [NSString string];

//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"定位" style:UIBarButtonItemStylePlain target:self action:@selector(baiduMap)];
    [self baiduMap];
}
#pragma mark 定位显示地点
- (void)baiduMap {
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    
    if (kCLAuthorizationStatusDenied == status || kCLAuthorizationStatusRestricted == status) {
        
        UIAlertController *alertControler = [UIAlertController alertControllerWithTitle:LanguageTool(@"提示") message:LanguageTool(@"请打开您的定位位置服务!") preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alertControler animated:YES completion:^{
            [self dismissViewControllerAnimated:YES completion:^{
                [self.navigationController popViewControllerAnimated:YES];
            }];
        }];
    } else {
        BMKMapView *mapView = [_myloca locationWithMapframe: self.view.frame];
        [self.view addSubview: mapView];
        [self searchButtonView];
    }

}
- (void)searchButtonView {
    self.searchView = [[UIView alloc] init];
    [self.view addSubview:self.searchView];
    self.searchView.backgroundColor = [UIColor whiteColor];
    [self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.mas_bottom).offset(-20);
        make.height.mas_equalTo(30);
        make.left.equalTo(self.view.mas_left).offset(20);
        make.right.equalTo(self.view.mas_right).offset(-20);
    }];
    [self searchHotel];
}

- (void)searchHotel {
    
    UIView *viewHotel = [[UIView alloc] init];
    viewHotel.layer.borderColor = [UIColor colorWithWhite:0.882 alpha:1.000].CGColor;
    viewHotel.layer.borderWidth = 0.5;
    [self.searchView addSubview:viewHotel];
    
    UIView *viewRestaurant = [[UIView alloc] init];
    [self.searchView addSubview:viewRestaurant];
    viewRestaurant.layer.borderColor = [UIColor colorWithWhite:0.882 alpha:1.000].CGColor;
    viewRestaurant.layer.borderWidth = 0.5;
    
    UIView *viewTourist = [[UIView alloc] init];
    [self.searchView addSubview:viewTourist];
    
    [viewHotel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.searchView.mas_top);
        make.left.equalTo(self.searchView.mas_left);
        make.right.equalTo(viewRestaurant.mas_left);
        make.bottom.equalTo(self.searchView.mas_bottom);
        make.width.equalTo(@[viewRestaurant, viewTourist]);
    }];
    
    [viewRestaurant mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.searchView.mas_top);
        make.left.equalTo(viewHotel.mas_right);
        make.right.equalTo(viewTourist.mas_left);
        make.bottom.equalTo(self.searchView.mas_bottom);
        make.width.equalTo(@[viewHotel, viewTourist]);
    }];
    
    [viewTourist mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.searchView.mas_top);
        make.left.equalTo(viewRestaurant.mas_right);
        make.right.equalTo(self.searchView.mas_right);
        make.bottom.equalTo(self.searchView.mas_bottom);
        make.width.equalTo(@[viewHotel, viewRestaurant]);
    }];
    
    // 酒店 餐厅 景点
    UIButton *buttonHotel = [UIButton buttonWithType:UIButtonTypeCustom];
    [buttonHotel setImage:[UIImage imageNamed:@"hotel-icon.png"] forState:UIControlStateNormal];
    [viewHotel addSubview:buttonHotel];
    [buttonHotel addTarget:self action:@selector(onClickHotel) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *buttonRestaurant = [UIButton buttonWithType:UIButtonTypeCustom];
    [buttonRestaurant setImage:[UIImage imageNamed:@"restaurant-icon.png"] forState:UIControlStateNormal];
    [viewRestaurant addSubview:buttonRestaurant];
    [buttonRestaurant addTarget:self action:@selector(onClickRestaurant) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *buttonTourist = [UIButton buttonWithType:UIButtonTypeCustom];
    [buttonTourist setImage:[UIImage imageNamed:@"tourist-icon.png"] forState:UIControlStateNormal];
    [viewTourist addSubview:buttonTourist];
    [buttonTourist addTarget:self action:@selector(onClickTourist) forControlEvents:UIControlEventTouchUpInside];
    
    [buttonHotel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewHotel.mas_top);
        make.bottom.equalTo(viewHotel.mas_bottom);
        make.width.mas_equalTo(40);
        make.centerX.equalTo(viewHotel.mas_centerX);
    }];
    [buttonRestaurant mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewRestaurant.mas_top);
        make.bottom.equalTo(viewRestaurant.mas_bottom);
        make.width.mas_equalTo(40);
        make.centerX.equalTo(viewRestaurant.mas_centerX);
    }];
    [buttonTourist mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewTourist.mas_top);
        make.bottom.equalTo(viewTourist.mas_bottom);
        make.width.mas_equalTo(40);
        make.centerX.equalTo(viewTourist.mas_centerX);
    }];
}

- (void)onClickHotel {
    
    NSLog(@"%@",self.locationName1);
    NSString *name = [NSString stringWithFormat:@"%@", self.locationName1];
    [_myloca onClickHotel:name facilities:@"酒店"];
}

- (void)onClickRestaurant {
    [_myloca onClickHotel:self.locationName1 facilities:@"餐厅"];
}

- (void)onClickTourist {
    [_myloca onClickHotel:self.locationName1 facilities:@"景点"];
}


// 设置当前位置地址
- (void)locationName:(NSString *)name {
    
    self.locationName1 = [NSString stringWithFormat:@"%@", name];
    NSLog(@"%@", self.locationName1);
}

#pragma mark 写地点定位
- (void)bbbbbb{
    [self.view addSubview:[self.myloca locationWithAddress:@"内蒙古赤峰" Mapframe:self.view.frame]];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
